package pl.oczadly.jabberclient.message.presenter;

import org.jivesoftware.smack.MessageListener;

import pl.oczadly.jabberclient.message.model.IMessageModel;
import pl.oczadly.jabberclient.message.model.MessageModel;
import pl.oczadly.jabberclient.message.view.MessageView;

public class MessagePresenter implements IMessagePresenter {

	private String id;
	private String name;
	
	private String message;
	
	private IMessageModel model;
	private MessageView messageView;
	
	public MessagePresenter( MessageView view, String id, String name ) {
		this.messageView = view;
		this.id = id;
		this.name = name;
		model = new MessageModel( this.id, this.name );
	}
	
	public void addChatManager( MessageListener messageListener ) {
		model.addChatManager( messageListener );
	}
	
	public void sendMessage( String message ) {
		model.sendMessage( message );
	}

	public void ignore( MessageListener messageListener ) {
		model.sendMessage( "IGNORED" );
		model.removeChatManager( messageListener );
	}
	
	public String getMessage() {
		return message;
	}
	
	public void receiveMessage( String from, String body ) {
		messageView.setMessage( from, body );
	}

}
